package com.yiwei.zxp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.zxp.R;
import com.yiwei.zxp.api.model.BuyerOrderDetailModel;
import com.yiwei.zxp.api.model.ItemGoodsDetail;
import com.yiwei.zxp.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class BuyerOrderDetailAdapter extends ItemAdapter<ItemGoodsDetail, BuyerOrderDetailAdapter.DefaultHolder> {


    private final int x24;
    private Context context;

    public BuyerOrderDetailAdapter(Context context) {
        super(context);
        this.context = context;
        x24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_buy_order_detail, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ItemGoodsDetail item = getItem(position);
        Spanned txt_right = Spans.with(context).font("￥" + item.price, x24, 0xff000000).
                font("\n运费:￥" + item.deliver_fee, x24, 0xff000000).
                font("\nx" + item.num, x24, 0xff000000).
                build();
        holder.txtRightInfo.setText(txt_right);
        holder.txtTitle.setText(item.title);
        if (item.photos != null && item.photos.size() != 0) {
            Glide.with(context).load(item.photos.get(0)).asBitmap().centerCrop().into(holder.imgGoods);
        }
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_goods)
        ImageView imgGoods;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_right_info)
        TextView txtRightInfo;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
